﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Diagnostics;
using System.Security.Cryptography;
using System.ComponentModel;

namespace FindDuplicateFile
{
    /// <summary>
    /// Class de base d'un Noeud dans le file system
    /// Un noeud peut être soit un dossier, soit un fichier
    /// </summary>
    public abstract class FSNode : INotifyPropertyChanged
    {
        public abstract void OpenDirectory();
        public abstract void OpenFile();
        public abstract void Delete();

        public string ToBeautifulSize(long lSize)
        {
            if (lSize == 0)
                return string.Empty;
            else if (lSize > 1024 * 1024 * 1024)
                return string.Format("{0} Go", lSize / (1024 * 1024 * 1024));
            else if (lSize > 1024 * 1024)
                return string.Format("{0} Mo", lSize / (1024 * 1024));
            else if (lSize > 1024)
                return string.Format("{0} Ko", lSize / 1024);
            else
                return lSize.ToString();
        }

        public string Name { get {return m_Name;} set {if (value != m_Name) {m_Name = value;NotifyPropertyChanged("Name");}} }
        private string m_Name;
        public string Path { get { return m_Path; } set { if (value != m_Path) { m_Path = value; NotifyPropertyChanged("Path"); } } }
        private string m_Path;
        public long Size { get { return m_Size; } set { if (value != m_Size) { m_Size = value; NotifyPropertyChanged("Size"); } } }
        private long m_Size;
        public string BeautifulSize 
        { 
            get 
            {
                return ToBeautifulSize(m_Size); 
            } 
        }
        public DateTime CreationTime { get { return m_CreationTime; } set { if (value != m_CreationTime) { m_CreationTime = value; NotifyPropertyChanged("CreationTime"); } } }
        private DateTime m_CreationTime;
        public DateTime LastAccessTime { get { return m_LastAccessTime; } set { if (value != m_LastAccessTime) { m_LastAccessTime = value; NotifyPropertyChanged("LastAccessTime"); } } }
        private DateTime m_LastAccessTime;
        public DateTime LastWriteTime { get { return m_LastWriteTime; } set { if (value != m_LastWriteTime) { m_LastWriteTime = value; NotifyPropertyChanged("LastWriteTime"); } } }
        private DateTime m_LastWriteTime;

        public override string ToString() 
        {
            return Name;
        }

        #region Fucking/Garbage for : INotifyPropertyChanged
        public event PropertyChangedEventHandler PropertyChanged;
        protected void NotifyPropertyChanged(String info)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(info));
            }
        }
        #endregion Fucking/Garbage for : INotifyPropertyChanged
    }
}
